/**
 * Class: DVertex
 *
 * Purpose: 
 *
 * Created: Feb 21, 2010 @ 2:08:42 PM
 * @author Ken
 */
package org.openfantasia.util.math.geometry;

import org.openfantasia.util.math.DPoint3;

public class DEdge {

	private DPoint3 p0;

	private DPoint3 p1;


	public DEdge() {
	}


	public DEdge(DPoint3 p0, DPoint3 p1) {
		this.p0 = p0;
		this.p1 = p1;
	}


	public DEdge(DEdge that) {
		copy(that);
	}


	public DEdge copy() {
		return new DEdge(this);
	}


	public void copy(DEdge that) {
		this.p0 = that.p0.copy();
		this.p1 = that.p1.copy();
	}


	public DPoint3 getP0() {
		return p0;
	}


	public void setP0(DPoint3 p0) {
		this.p0 = p0;
	}


	public DPoint3 getP1() {
		return p1;
	}


	public void setP1(DPoint3 p1) {
		this.p1 = p1;
	}


	public DEdge translate(DPoint3 off) {
		p0.add(off);
		p1.add(off);
		return this;
	}


	public DEdge scale(double scale) {
		p0.scale(scale);
		p1.scale(scale);
		return this;
	}


	public DEdge scale(DPoint3 scale) {
		p0.scale(scale);
		p1.scale(scale);
		return this;
	}


	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (!(o instanceof DEdge)) {
			return false;
		}

		DEdge that = (DEdge) o;

		if ((p0 == null) || (p1 == null)) {
			return false;
		}

		return (p0.equals(that.p0) && p1.equals(that.p1)) || (p0.equals(that.p1) && p1.equals(that.p0));
	}


	@Override
	public int hashCode() {
		int result = p0 != null ? p0.hashCode() : 0;
		result = 31 * result + (p1 != null ? p1.hashCode() : 0);
		return result;
	}


	@Override
	public String toString() {
		return "DEdge{" + p0 + ", " + p1 + '}';
	}
}